<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="/static/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/static/css/plugins/iCheck/skins/square/green.css" rel="stylesheet">
    <script src="/static/js/jquery.min.js"></script>
    <script src="/static/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="/static/js/plugins/iCheck/icheck.js"></script>
    <script type="text/javascript">
        $(function(){

            $("#selectAll").on('ifClicked',function(event){
               // alert($(this).is(":checked"));
                //alert(event.type + ' callback');
                if(!$(this).is(":checked")){
                    $('input').iCheck('check');
                } else {
                    $('input').iCheck('uncheck');
                }
            });

            //自己实现，如果下面的checkbox 全部选中，全选checkbox 也被选中，如果有一个没选中，全选的checkbox 不被选中
            $(".check").on('ifClicked',function(event){
                var count = 0;
                if($(this).is(":checked")){   //点击时选中，点击后 变为未选中
                    $('#selectAll').iCheck('uncheck');
                } else {
                    $(".check").each(function(){
                         if(!$(this).is(":checked")){
                             count ++;
                             if(count > 1){
                                 $('#selectAll').iCheck('uncheck');
                                // alert("未选中数量大于1");
                                 return;
                             }
                         }
                    });
                    if(count <= 1){
                        $('#selectAll').iCheck('check');
                    }
                }
            });

            $('input').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
                increaseArea: '20%' // optional
            });
        });


        window.getChoseId=function () {
            var value=new Array();
            var radio = document.getElementsByClassName("check");
            for(var i = 0;i<radio.length;i++)
            {
                if(radio[i].checked==true && radio[i].checked != null)
                {
                    value[i]= radio[i].value;
                }
            }
            return value;
        };


    </script>
</head>
<body>

<ul>



    <div class="checkbox">
        <div style="float: left">
            <input type="checkbox" id="selectAll">
        </div>
        <label></label>
    </div>

    <#list roleList as role>
          <div class="checkbox">
              <div style="float: left">
                  <#if role.isHas>
                      <input type="checkbox" class="check" value="${role.roleId}" checked="checked">
                  <#else>
                     <input type="checkbox" class="check" value="${role.roleId}">
                  </#if>
              </div>
              <label>
                  ${role.roleName} ( ${role.desc} )
              </label>
          </div>
    </#list>


</ul>
</body>
</html>
